package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroServiceDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroService;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroServiceDao")
public class DockerMicroServiceDaoImpl extends BaseDaoImpl implements IDockerMicroServiceDao{

	@Override
	public List<DockerMicroService> selectByCreateUserIdAndAppIdAndServiceCode(Long createUserId, Long appId, String serviceCode) {
		DockerMicroService service = new DockerMicroService();
		service.setCreateUserId(createUserId);
		service.setCode(serviceCode);
		service.setDockerMicroAppId(appId);
		return this.selectByExample(service);
	}

	@Override
	public DockerMicroService selectById(Long id) {
		DockerMicroService service = new DockerMicroService();
		service.setId(id);
		return this.selectByPrimaryKey(service);
	}

	@Override
	public List<DockerMicroService> selectByDockerMicroAppId(Long appId) {
		String sql = "select * from docker_micro_service where docker_micro_app_id = ?";
		List<Object> params = new ArrayList<Object>();
		params.add(appId);
		return super.jdbcFindList(sql, DockerMicroService.class, params);
	}

	@Override
	public void deleteById(Long serviceId) {
		DockerMicroService service = new DockerMicroService();
		service.setId(serviceId);
		super.deleteByPrimaryKey(service);
	}

	@Override
	public void updateStateAndReleaseStateAndDesc(Long id, String state, String releaseState,
			String releaseStateDescription, String lastUpdateTime) {
		DockerMicroService service = new DockerMicroService();
		service.setId(id);
		service.setState(state);
		service.setReleaseState(releaseState);
		service.setReleaseStateDescription(releaseStateDescription);
		service.setLastUpdateTime(lastUpdateTime);
		super.updateSelectiveByPrimaryKey(service);
	}

	@Override
	public void updateAutoscalePolicyId(Long id, Long autoscalePolicyId) {
		DockerMicroService service = new DockerMicroService();
		service.setId(id);
		service.setAutoscalePolicyId(autoscalePolicyId);
		super.updateSelectiveByPrimaryKey(service);
	}

	@Override
	public void updateIsAutoscalableAndAutoscalePolicyId(Long id, Integer isAutoscalable, Long autoscalePolicyId) {
		DockerMicroService service = new DockerMicroService();
		service.setId(id);
		service.setIsAutoScalable(isAutoscalable);
		service.setAutoscalePolicyId(autoscalePolicyId);
		super.updateSelectiveByPrimaryKey(service);
		
	}

	

	
	
	
}
